﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace FIPSSearch
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("1 for fast mode (ADO), 2 for slow mode (EF)");
            int mode = int.Parse(Console.ReadLine());

            var connString = FIPSSearch.Properties.Settings.Default.CensusToolsConnection;
            //var connString = "data source=ERIS\SQLEXPRESS;initial catalog=CensusTools;integrated security=True;";
            //var connString = "data source=ERIS;initial catalog=CensusTools;integrated security=True;";

            var sourceFile = new FileInfo("national_county.txt");
            if (!sourceFile.Exists)
            {
                Console.WriteLine("THe file is missing: " + sourceFile.FullName);
            }
            else
            {
                var repo = new CensusRepository(connString);
                var list = repo.ParseCountyFile(sourceFile);
                repo.ClearTable();
                if (mode == 1)
                {
                    repo.LoadTableFast(list);
                }
                else
                {
                    repo.LoadTable(list);
                }
            }


            var sourceFile2 = new FileInfo("national_schdist.txt");
            if (!sourceFile2.Exists)
            {
                Console.WriteLine("The file is missing: " + sourceFile2.FullName);
            }
            else
            {
                var repos = new DistrictRepository(connString);
                var list = repos.ParseSchoolDistrictFile(sourceFile2);
                repos.ClearTable();
                if (mode == 1)
                {
                    repos.LoadTableFast(list);
                }
                else
                {
                    repos.LoadTable(list);
                }
            }
            Console.WriteLine("Done");
            Console.ReadLine();
        }
    }

}
